package com.woldier.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woldier.entity.ShoppingCart;
import com.woldier.mapper.ShoppingCartMapper;
import com.woldier.service.ShoppingCartService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {

    /*通过uid获取*/
    @Override
    public List<ShoppingCart> getByUid(Long uid) {

        LambdaQueryWrapper<ShoppingCart> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        /*查询条件user_id = ?*/
        lambdaQueryWrapper.eq(ShoppingCart::getUserId,uid);

        List<ShoppingCart> list = this.list(lambdaQueryWrapper);



        return list;
    }


    /*通过uid 并且通过dish_id 或者 category_id 获取*/
    @Override
    public ShoppingCart getByUid(ShoppingCart shoppingCart) {
        LambdaQueryWrapper<ShoppingCart> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        /* user_id = ?
        *  如果 DishId 存在则 dish_id = ?
        *   如果 SetmealId 存在则 setmeal_Id = ?
        * */
        lambdaQueryWrapper.eq(ShoppingCart::getUserId,shoppingCart.getUserId())
                .eq(shoppingCart.getDishId()!=null,ShoppingCart::getDishId,shoppingCart.getDishId())
                .eq(shoppingCart.getSetmealId()!=null,ShoppingCart::getSetmealId,shoppingCart.getSetmealId());

        ShoppingCart one = this.getOne(lambdaQueryWrapper);
        return one;
    }
}
